﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

using MaxStudio.Concrete.DBUtility;

namespace MaxStudio.Concrete.Server.Dao
{
    public partial class ConcreteDaoDataContext : System.Data.Linq.DataContext
    {
        #region FunctionGroup 

        public List<tb_FunctionGroup> getAllFunctionGroup()
        {
            var query = (from obj in this.tb_FunctionGroups
                         where obj.IsDelete == 0
                         select obj).ToList();
            return query;
        }

        public tb_FunctionGroup getFunctionGroupByID(int ID)
        {
            return this.tb_FunctionGroups.SingleOrDefault(tb_FunctionGroups => tb_FunctionGroups.Id == ID);
        }

        public void createFunctionGroup(tb_FunctionGroup instance)
        {
            tb_FunctionGroups.InsertOnSubmit(instance);
            this.SubmitChanges();
        }

        public void deleteFunctionGroup(tb_FunctionGroup instance)
        {
            tb_FunctionGroup functionGroups = tb_FunctionGroups.SingleOrDefault(p => p.Id == instance.Id);
            tb_FunctionGroups.DeleteOnSubmit(functionGroups);
            this.SubmitChanges();
        }

        public void modifyFunctionGroup(string groupName, string description, int modifyBy, DateTime modifyDate, int isDelete, int id)
        {
            tb_FunctionGroup instance = this.tb_FunctionGroups.SingleOrDefault(p => p.Id==id);

            instance.GroupName = groupName;
            instance.Description = description;
            instance.ModifyBy = modifyBy;
            instance.ModifyDate = modifyDate;
            instance.IsDelete = isDelete;

            this.SubmitChanges();
        }

        #endregion 

        #region Mapping_FunctionGroup

        public List<tb_Mapping_FunctionGroup> getFunctionGroupMappingByGroupId(int GroupId)
        {
            var query = (from obj in this.tb_Mapping_FunctionGroups
                         where obj.FunctionGroupId == GroupId
                         
                         select obj).ToList();
            return query;
        }

        public void createFunctionGroupMapping(tb_Mapping_FunctionGroup instance)
        {
            tb_Mapping_FunctionGroups.InsertOnSubmit(instance);
            this.SubmitChanges();
        }

        public void deleteFunctionGroupMapping(int GroupId)
        { 
            List<tb_Mapping_FunctionGroup> deleteList = getFunctionGroupMappingByGroupId(GroupId);
            foreach (tb_Mapping_FunctionGroup deleteEntity in deleteList)
            {
                tb_Mapping_FunctionGroups.DeleteOnSubmit(deleteEntity);

            }
            this.SubmitChanges();
        }

        #endregion

    }
}
